﻿<%@ page contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="/extjs/include/all.jsp"%>
<title>商业银行个人信贷管理系统 用户名：运行中心岗 操作号：800088 岗位运行中心岗 部门：总部</title>
<script type="text/javascript">
var userName = '${__SATURN_AUTORITY_USER__.username}';
var id = '${__SATURN_AUTORITY_USER__.id}';
var userType = '${__SATURN_AUTORITY_USER__.usertype}';
var menuList = '${__SATURN_AUTORITY_MENU__}';
var saturnClickTab;
Ext.onReady(function() {  
    Ext.QuickTips.init();
    
    saturnClickTab = function(tabId, tabTitle, path) {
		var frameId = 'frame' + tabId;
		var tablink ;

		if('http://' == path.substring(0,7)){
			tablink =  path;	
		} else {
			tablink = "<%=request.getContextPath()%>" + path;
		}
		
		var tabPanel = Ext.getCmp("saturn-tab-panel");
		var tab = tabPanel.getItem(tabId);
		if(!tab){
			tab = tabPanel.add(new Ext.Panel({
			            id: tabId,
			            title: tabTitle,
			            closable: true,
			         //   destroy: function() {
			            	//由于在删除的时候不会删除iframe,所以会造成内存泄露
			            	//if (iframe.src) {
							//	iframe.src = "javascript:false";
							//} 
			        //    },
			            html:'<iframe src="' + tablink + '" id="' + frameId + '" name="' + tabTitle+ '" width="100%" marginwidth="0" height="100%" marginheight="0" scrolling="auto" frameborder="0"></iframe>'  
			    }));
			tab.show();
			tabPanel.setActiveTab(tab);
        }else{
            tabPanel.setActiveTab(tab);
        }
	}
	
	//try {
	
	   var saturnTree = new Ext.tree.TreePanel({
			title:'主菜单',
			id:'saturn-tree',//设置一个id
			autoScroll:true,//自动出现滚动条
			enableDD:false,//是否支持拖拽效果
			containerScroll: true,//是否支持滚动条
			rootVisible:false,//是否显示跟节点
			loader:new Ext.tree.TreeLoader({
				dataUrl:'<%=request.getContextPath()%>/edu.ccut.saturn.authority.impl::/loginModule/action/GetUserMenuJson.action?username=' + id + '&usertype=' + userType
			})
		});
		
		var treeRootNode = new Ext.tree.AsyncTreeNode({
			text:'根节点',
			id:'saturn-tree-root'
		});
		
		saturnTree.setRootNode(treeRootNode);
		saturnTree.on('click', function(node) {
				if(!node.isLeaf()){   
		            return false;   
		        }
				saturnClickTab(node.id, node.text, node.attributes.path);
		}, this);
		
		saturnTree.on('click', function(node) {
				if(!node.isLeaf()){   
		            return false;   
		        }
				saturnClickTab(node.id, node.text, node.attributes.path);
		}, this);
		
		//-----------------子菜单----------------------
 		var saturnSubTree = new Ext.tree.TreePanel({
			title:'子菜单',
			id:'saturn-sub-tree',
			autoScroll:true,
			enableDD:false,
			containerScroll: true,
			rootVisible:false,
			loader:new Ext.tree.TreeLoader({	
				dataUrl:'<%=request.getContextPath()%>/edu.ccut.saturn.authority.impl::/loginModule/action/GetUserMenuJson.action?username=' + id + '&usertype=' + userType
			})
		});
		
		var treeSubRootNode = new Ext.tree.AsyncTreeNode({
			text:'根节点',
			id:'saturn-tree-sub-root'
		});
		saturnSubTree.setRootNode(treeSubRootNode);
		saturnSubTree.on('click', function(node) {
				if(!node.isLeaf()){   
		            return false;   
		        }
				saturnClickTab(node.id, node.text, node.attributes.path);
		}, this);	
		//------------------------------------------
		
	   	var saturnMain = new Ext.Viewport({
	        layout:'border',
			items:[
				new Ext.BoxComponent({ 
					region:'north',
					el: 'north',
					margins:'5',
					height:50
				}),
				new Ext.BoxComponent({ 
					region:'south',
					el: 'south',
					height:56,
					split:true,
					margins:'0 5 0 5'
				}),{
					region:'west',
					id:'west',
					title:'导航栏',
					split:true,
					width: 200,
					minSize: 175,
					maxSize: 400,
					collapsible: true,
					margins:'0 0 0 5',
					layout:'accordion',
					collapsed:false,
					layoutConfig:{
						animate:true
					},
					items: [saturnTree,saturnSubTree]
				},
				new Ext.TabPanel({
					id:"saturn-tab-panel",
	                region:'center',
	                deferredRender:false,
	                tabWidth:135,
        			enableTabScroll:true,
	                activeTab: 0,
	                margins:'0 5 0 0',
	                items:[{
	                    title: '首页',
	                    autoScroll:true, 
	                    html:'<iframe src="' + '<%=request.getContextPath()%>/extjs/portal/portal.jsp' + '" id="portal" name="portal" width="100%" marginwidth="0" height="100%" marginheight="0" scrolling="auto" frameborder="0"></iframe>' 
	                }]
	            })
			]
		});
		
		function saturnCreateMenuToolbar(jsonMenus) {
			var tb = new Ext.Toolbar();    
			tb.render('toolbar');
			for (var i = 0; i < jsonMenus.length; ++i) {
				var menu = jsonMenus[i];
				var menuItem = new Ext.menu.Menu();
				var menuId = menu.id;
				saturnChangeMenuChildrenToMenu(menu);
				tb.add({
					id: menuId, 
					text: menu.text,
					scope: this,
					menu: menu.menu,
					handler: function(bar) {
						loadModuleMenu(bar.id)
					}
				});
			}
		}
		
		function loadModuleMenu(menuId) {
				var loader = saturnSubTree.getLoader();   
				saturnSubTree.on('beforeload', function(){
            		loader.dataUrl = '<%=request.getContextPath()%>/edu.ccut.saturn.authority.impl::/loginModule/action/GetUserSubMenuJson.action?username=' + id + '&usertype=' + userType + '&menuId=' + menuId ;    
				})
				saturnSubTree.root.reload();//让根节点重新加载
		}
		
		function saturnMenuItemClick(item) {
			saturnClickTab(item.id, item.text, item.path);
		}
		
		function saturnChangeMenuChildrenToMenu(menu) {
			if (menu.leaf == false) {
				var children = menu.children;
				menu.menu = menu.children;
				
				for (var i = 0; i < children.length; ++i) {
					saturnChangeMenuChildrenToMenu(children[i]);
				}
			} else {
				menu.handler = saturnMenuItemClick;
			}
		}
		
		//工具条
		if(menuList != ''){
			var saturnJsonMenus = Ext.util.JSON.decode(menuList);
			saturnCreateMenuToolbar(saturnJsonMenus);
		}
	//} catch(e) {
	//	alert(" name: " + e.name +
	//	" \nmessage: " + e.message +
	//	" \nlineNumber: " + e.lineNumber +
	//	" \nfileName: " + e.fileName +
	//	" \nstack: " + e.stack);
	//} 
	
	var cssArray = [['default','Ext Blue'],
					['gray','Gray Theme'],
					['chocolate','Chocolate Theme'],
					['peppermint','Peppermint Theme'],
					['silverCherry','SilverCherry Theme'],
					['black','Black Theme'],
					['green','Green Theme'],
					['darkgray','Darkgray Theme'],
					['indigo','Indigo Theme'],
					['olive','Olive Theme'],
					['galdaka','Galdaka Theme'],
					['purple','Purple Theme'],
					['slate','Slate Theme'],
					['slickness','Slickness Theme']];
					
	var cssStore = new Ext.data.SimpleStore({
		fields:[{name:'key'},{name:'value'}]
	});
	
	cssStore.loadData(cssArray);
	
	var extCssTheme = new Ext.form.ComboBox({
            name: 'theme_show',
            id:'theme_show',
            store: cssStore,
	        displayField:'value',
	        valueField :'key', 
	        hiddenName: 'cssTheme',
	        typeAhead: true,
	        mode: 'local',
	        forceSelection: true,
	        triggerAction: 'all',
	        selectOnFocus:true,
	        editable: false,
	        emptyText:'请选择皮肤...',
	        anchor:'95%'
	});
	extCssTheme.render('exttheme');
	var cssNum = 0;
	function getThemeText(themeKey){
			for(var i = 0, n = cssArray.length; i < n; i++){
	       		if(cssArray[i][0] == themeKey){
	       			cssNum = i;
	       			return cssArray[i][1];
	       		}
	       	}
	}
	setThemeValue = function(){
		if(theme){    
			Ext.get('theme_show').dom.value = getThemeText(theme);
			extCssTheme.emptyText = getThemeText(theme);
			Ext.get('cssTheme').dom.value = theme;
	    } else {
	    	Ext.get('theme_show').dom.value = cssArray[0][1];
			Ext.get('cssTheme').dom.value = cssArray[0][0];
	    }
	    return true;
	}
	setThemeValue();
	extCssTheme.on('select',function(){
		changeFace();
	});
	
	function changeFace(){
	     Ext.state.Manager.set('exttheme', Ext.get('cssTheme').dom.value);
	        setTimeout(function(){
	            window.location.reload();
	       }, 250);
	}	
	
	var quitButton = new Ext.Button({
		text:'退出',
		renderTo:'quit',
        handler: function(){
             window.location = 'login.jsp'
        }
	});
});
</script>
</head>
<body>
	<div id="north">
			<table id="northTable" border="0" width="100%">
				<tr>
					<td id="tableMain">
					<h1>saturn平台权限管理系统</h1>
					</td>
					<td id="cssMain" align="right">
							<div id='quit'></div>
					</td><td width="120">
							<span style="white-space: pre">	</span>		
							<span style="text-align: right; font-size: 12px"><B>皮肤:</B></span>
					</td><td width="160">	
							<span id="exttheme"></span>
					</td>
				</tr>
			</table>
			<div id="toolbar"></div>
	</div>
	<div id="west"></div>
	<div id="center"></div>
	<div id="south">
	<p>CopyRight 2006~2009 @ CCUT</p>
	</div>
	</body>
</html>